/*   1:    */ package com.atomikos.datasource.xa.jdbc;
/*   2:    */ 
/*   3:    */ import com.atomikos.datasource.ResourceException;
/*   4:    */ import com.atomikos.datasource.xa.XATransactionalResource;
/*   5:    */ import com.atomikos.datasource.xa.XidFactory;
/*   6:    */ import java.sql.SQLException;
/*   7:    */ import java.util.Stack;
/*   8:    */ import javax.sql.XAConnection;
/*   9:    */ import javax.sql.XADataSource;
/*  10:    */ import javax.transaction.xa.XAResource;
/*  11:    */ 
/*  12:    */ public class JdbcTransactionalResource
/*  13:    */   extends XATransactionalResource
/*  14:    */ {
/*  15:    */   private XADataSource xads_;
/*  16:    */   private XAConnection conn_;
/*  17:    */   private String user_;
/*  18:    */   private String password_;
/*  19:    */   
/*  20:    */   public JdbcTransactionalResource(String serverName, XADataSource xads)
/*  21:    */   {
/*  22: 73 */     super(serverName);
/*  23: 74 */     this.xads_ = xads;
/*  24: 75 */     if (this.xads_ == null) {
/*  25: 76 */       throw new RuntimeException("Null XADataSource argument");
/*  26:    */     }
/*  27: 77 */     this.conn_ = null;
/*  28:    */   }
/*  29:    */   
/*  30:    */   public JdbcTransactionalResource(String serverName, XADataSource xads, XidFactory factory)
/*  31:    */   {
/*  32: 96 */     super(serverName, factory);
/*  33: 97 */     this.xads_ = xads;
/*  34: 98 */     this.conn_ = null;
/*  35:    */   }
/*  36:    */   
/*  37:    */   private String getUser()
/*  38:    */   {
/*  39:108 */     String ret = "";
/*  40:109 */     if (this.user_ != null) {
/*  41:110 */       ret = this.user_;
/*  42:    */     }
/*  43:112 */     return ret;
/*  44:    */   }
/*  45:    */   
/*  46:    */   private String getPassword()
/*  47:    */   {
/*  48:122 */     String ret = "";
/*  49:123 */     if (this.password_ != null) {
/*  50:124 */       ret = this.password_;
/*  51:    */     }
/*  52:125 */     return ret;
/*  53:    */   }
/*  54:    */   
/*  55:    */   protected synchronized XAResource refreshXAConnection()
/*  56:    */     throws ResourceException
/*  57:    */   {
/*  58:137 */     XAResource res = null;
/*  59:139 */     if (this.conn_ != null) {
/*  60:    */       try
/*  61:    */       {
/*  62:141 */         this.conn_.close();
/*  63:    */       }
/*  64:    */       catch (Exception err) {}
/*  65:    */     }
/*  66:    */     try
/*  67:    */     {
/*  68:150 */       this.conn_ = createXAConnection();
/*  69:151 */       if (this.conn_ != null) {
/*  70:152 */         res = this.conn_.getXAResource();
/*  71:    */       }
/*  72:    */     }
/*  73:    */     catch (SQLException sql)
/*  74:    */     {
/*  75:155 */       Stack errors = new Stack();
/*  76:156 */       errors.push(sql);
/*  77:157 */       throw new ResourceException("Error in getting XA resource", errors);
/*  78:    */     }
/*  79:161 */     return res;
/*  80:    */   }
/*  81:    */   
/*  82:    */   public void setUser(String user)
/*  83:    */   {
/*  84:177 */     this.user_ = user;
/*  85:    */   }
/*  86:    */   
/*  87:    */   public void setPassword(String password)
/*  88:    */   {
/*  89:192 */     this.password_ = password;
/*  90:    */   }
/*  91:    */   
/*  92:    */   public void close()
/*  93:    */     throws ResourceException
/*  94:    */   {
/*  95:202 */     super.close();
/*  96:    */     try
/*  97:    */     {
/*  98:204 */       if (this.conn_ != null) {
/*  99:205 */         this.conn_.close();
/* 100:    */       }
/* 101:    */     }
/* 102:    */     catch (SQLException err) {}
/* 103:    */   }
/* 104:    */   
/* 105:    */   private XAConnection createXAConnection()
/* 106:    */   {
/* 107:216 */     XAConnection conn = null;
/* 108:    */     try
/* 109:    */     {
/* 110:218 */       if ("".equals(getUser())) {
/* 111:219 */         conn = this.xads_.getXAConnection();
/* 112:    */       } else {
/* 113:221 */         conn = this.xads_.getXAConnection(getUser(), getPassword());
/* 114:    */       }
/* 115:    */     }
/* 116:    */     catch (SQLException noConnection)
/* 117:    */     {
/* 118:226 */       conn = null;
/* 119:    */     }
/* 120:228 */     return conn;
/* 121:    */   }
/* 122:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\transactions-jta\3.7.0\transactions-jta-3.7.0.jar
 * Qualified Name:     com.atomikos.datasource.xa.jdbc.JdbcTransactionalResource
 * JD-Core Version:    0.7.0.1
 */